package me.hetong.caigou.mapper;

import me.hetong.caigou.entity.Qipu;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface WenMapper {

    @Update("create table if not exists wen\n" +
            "(\n" +
            "    id          TEXT\n" +
            "        primary key,\n" +
            "    title       TEXT,\n" +
            "    match       TEXT,\n" +
            "    match_date  TEXT,\n" +
            "    lun         TEXT,\n" +
            "    red         TEXT,\n" +
            "    red_team    TEXT,\n" +
            "    black       TEXT,\n" +
            "    black_team  TEXT,\n" +
            "    result      TEXT,\n" +
            "    arr         TEXT,\n" +
            "    create_time TEXT,\n" +
            "    remark      TEXT\n" +
            ");\n" +
            "\n")
    void createTable();

    @Select("select id,\n" +
            "       title,\n" +
            "       match,\n" +
            "       match_date as mathDate,\n" +
            "       lun,\n" +
            "       red,\n" +
            "       red_team  as  redTeam,\n" +
            "       black,\n" +
            "       black_team as blackTeam,\n" +
            "       result,\n" +
            "       arr,\n" +
            "       create_time as createTime,\n" +
            "       remark\n" +
            "from wen a where a.id = #{id}")
    Qipu queryById(@Param("id") String id);

    @Select("select id,\n" +
            "       title,\n" +
            "       match,\n" +
            "       match_date as mathDate,\n" +
            "       lun,\n" +
            "       red,\n" +
            "       red_team  as  redTeam,\n" +
            "       black,\n" +
            "       black_team as blackTeam,\n" +
            "       result,\n" +
            "       create_time as createTime,\n" +
            "       remark\n" +
            "from wen a\n" +
            "order by a.create_time desc limit #{start},10")
    List<Qipu> list(@Param("start") int start);

    @Select("select count(a.id)\n" +
            "from wen a\n" +
            "where a.id = #{id}")
    Integer countById(@Param("id") String id);

    @Delete("delete\n" +
            "from wen\n" +
            "where id = #{id}")
    void deleteById(@Param("id") String id);

    @Insert("INSERT INTO wen (" +
            "id," +
            "title," +
            "match, " +
            "match_date, " +
            "lun, " +
            "red, " +
            "red_team, " +
            "black, " +
            "black_team, " +
            "result, " +
            "arr, " +
            "create_time," +
            "remark) VALUES (" +
            "#{wen.id}," +
            "#{wen.title}," +
            "#{wen.match}," +
            "#{wen.matchDate}," +
            "#{wen.lun}," +
            "#{wen.red}," +
            "#{wen.redTeam}," +
            "#{wen.black}," +
            "#{wen.blackTeam}," +
            "#{wen.result}," +
            "#{wen.arr}," +
            "#{wen.createTime}," +
            "#{wen.remark});")
    void insert(@Param("wen") Qipu qipu);

    @Select("select count(a.id) from wen a")
    int countAll();
}
